<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   每个 Python 程序员都要知道的日志实践  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/19906.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466461234: Accept with keywords: (title(0.2):Python,程序员,日志,数盟,社区, topn(0.166666666667):社区,程序,数盟,信息,行业资讯,名称,数据挖掘,级别,文件,配置文件,Python,句柄,职业规划,例子,调试信息,文章,服务器,日志,记录,python,办法,问题,基础架构,语句,错误,标准,系统,消息,模块,时候).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    每个 Python 程序员都要知道的日志实践
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    每个 Python 程序员都要知道的日志实践 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,69] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/19906.html">
          每个 Python 程序员都要知道的日志实践
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,714 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        出处：
        <a href="http://python.jobbole.com/81666/">
         伯乐在线
        </a>
       </p>
       <p>
        在现实生活中，记录日志非常重要。银行转账时会有转账记录；飞机飞行过程中，会有黑盒子（飞行数据记录器）记录飞行过程中的一切。如果有出现什么问题，人们可以通过日志数据来搞清楚到底发生了什么。
       </p>
       <p>
        对于系统开发、调试以及运行，记录日志都是同样的重要。如果没有日志记录，程序崩溃时你几乎就没办法弄明白到底发生了什么事情。举个例子，当你在写一个服务器程序时，记录日志是非常有必要的。下面展示的就是 EZComet.com 服务器的日志文件截图。
       </p>
       <p>
        <img src="http://ww2.sinaimg.cn/mw690/b254dc71gw1etm9awziifj20ir0bs108.jpg"/>
       </p>
       <p>
        服务崩溃后，如果没有日志，我几乎没办法知道到底发生了错误。日志不仅对于服务器很重要，对于桌面图形应用同样十分重要。比如，当你的客户的 PC 机程序崩溃时，你可以让他们把日志文件发给你，这样你就可以找到问题到底出在哪儿。相信我，在不同的 PC 环境下，你永远不会知道会有怎样奇怪的问题。我曾经就接收到过这样的错误日志。
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_236051">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python value">
                2011
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python value">
                08
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python value">
                22
               </code>
               <code class="python value">
                17
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                52
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                54
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python value">
                828
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python plain">
                root
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python plain">
                ERROR
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python plain">
                [Errno
               </code>
               <code class="python value">
                10104
               </code>
               <code class="python plain">
                ] getaddrinfo failed
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                Traceback (most recent call last):
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "&lt;string&gt;"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                124
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                main
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "&lt;string&gt;"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                20
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                __init__
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/wx._core"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                7978
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                __init__
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/wx._core"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                7552
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                _BootstrapApp
               </code>
              </div>
              <div class="line number7 index6 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "&lt;string&gt;"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                84
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                OnInit
               </code>
              </div>
              <div class="line number8 index7 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/twisted.internet.wxreactor"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                175
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                install
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/twisted.internet._threadedselect"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                106
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                __init__
               </code>
              </div>
              <div class="line number10 index9 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/twisted.internet.base"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                488
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                __init__
               </code>
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/twisted.internet.posixbase"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                266
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                installWaker
               </code>
              </div>
              <div class="line number12 index11 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/twisted.internet.posixbase"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                74
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                __init__
               </code>
              </div>
              <div class="line number13 index12 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "h:workspaceprojectbuildpyi.win32mrdjoutPYZ1.pyz/socket"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                224
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                meth
               </code>
              </div>
              <div class="line number14 index13 alt1">
               <code class="python plain">
                gaierror: [Errno
               </code>
               <code class="python value">
                10104
               </code>
               <code class="python plain">
                ] getaddrinfo failed
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        我最终发现，这个客户的 PC 机被一种病毒感染，导致了调用 gethostname 函数失败。看吧，如果没有日志可以查你怎么可能知道这些。
       </p>
       <h3>
        打印输出不是个好办法
       </h3>
       <p>
        尽管记录日志非常重要，但是并不是所有的开发者都能正确地使用它。我曾看到一些开发者是这样记录日志的，在开发的过程中插入 print 语句，开发结束后再将这些语句移除。就像这样:
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_209842">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                print
               </code>
               <code class="python string">
                'Start reading database'
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                records
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                model.read_recrods()
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python functions">
                print
               </code>
               <code class="python string">
                '# records'
               </code>
               <code class="python plain">
                , records
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python functions">
                print
               </code>
               <code class="python string">
                'Updating record ...'
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python plain">
                model.update_records(records)
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python functions">
                print
               </code>
               <code class="python string">
                'done'
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        这种方式对于简单脚本型程序有用，但是如果是复杂的系统，你最好不要使用这样的方式。首先，你没办法做到在日志文件中只留下极其重要的消息。你会看到大量的消息日志。但是你却找不到任何有用的信息。你除了移除这输出语句这外，没别的办法控制代码，但是极有可能的是你忘记了移出那些没用的输出。再者，print 输出的所有信息都到了标准输出中，这将严重影响到你从标准输出中查看其它输出数据。当然，你也可以把消息输出到 stderr ，但是用 print 做日志记录的方式还是不好。
       </p>
       <h3>
        使用 python 的标准日志模块
       </h3>
       <p>
        那么，怎么样记录日志才是正确的呢？其实非常简单，使用 python 的标准日志模块。多亏 python 社区将日志做成了一个标准模块。它非常简单易用且十分灵活。你可以像这样使用日志系统：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_405884">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                logging.basicConfig(level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.INFO)
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number4 index3 alt1">
              </div>
              <div class="line number5 index4 alt2">
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Start reading database'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python comments">
                # read database here
               </code>
              </div>
              <div class="line number7 index6 alt2">
              </div>
              <div class="line number8 index7 alt1">
               <code class="python plain">
                records
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                {
               </code>
               <code class="python string">
                'john'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                55
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python string">
                'tom'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                66
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python plain">
                logger.debug(
               </code>
               <code class="python string">
                'Records: %s'
               </code>
               <code class="python plain">
                , records)
               </code>
              </div>
              <div class="line number10 index9 alt1">
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Updating records ...'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number11 index10 alt2">
               <code class="python comments">
                # update records here
               </code>
              </div>
              <div class="line number12 index11 alt1">
              </div>
              <div class="line number13 index12 alt2">
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Finish updating records'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        运行的时候就可看到：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_756250">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                INFO:__main__:Start reading database
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                INFO:__main__:Updating records ...
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                INFO:__main__:Finish updating records
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        你可能会问这与使用 print 有什么不同呢。它有以下的优势：
       </p>
       <ul>
        <li>
         你可以控制消息的级别，过滤掉那些并不重要的消息。
        </li>
        <li>
         你可决定输出到什么地方，以及怎么输出。
        </li>
       </ul>
       <p>
        有许多的重要性别级可供选择，debug、info、warning、error 以及 critical。通过赋予 logger 或者 handler 不同的级别，你就可以只输出错误消息到特定的记录文件中，或者在调试时只记录调试信息。让我们把 logger 的级别改成 DEBUG 再看一下输出结果：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_385407">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                logging.basicConfig(level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.DEBUG)
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        输出变成了：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_239009">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                INFO:__main__:Start reading database
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                DEBUG:__main__:Records: {
               </code>
               <code class="python string">
                'john'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                55
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python string">
                'tom'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                66
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                INFO:__main__:Updating records ...
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python plain">
                INFO:__main__:Finish updating records
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        正如看到的那样，我们把 logger 的等级改为 DEBUG 后，调试记录就出现在了输出当中。你也可以选择怎么处理这些消息。例如，你可以使用 FileHandler 把记录写进文件中：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_395190">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging
               </code>
              </div>
              <div class="line number2 index1 alt1">
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python plain">
                logger.setLevel(logging.INFO)
               </code>
              </div>
              <div class="line number5 index4 alt2">
              </div>
              <div class="line number6 index5 alt1">
               <code class="python comments">
                # create a file handler
               </code>
              </div>
              <div class="line number7 index6 alt2">
              </div>
              <div class="line number8 index7 alt1">
               <code class="python plain">
                handler
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.FileHandler(
               </code>
               <code class="python string">
                'hello.log'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python plain">
                handler.setLevel(logging.INFO)
               </code>
              </div>
              <div class="line number10 index9 alt1">
              </div>
              <div class="line number11 index10 alt2">
               <code class="python comments">
                # create a logging format
               </code>
              </div>
              <div class="line number12 index11 alt1">
              </div>
              <div class="line number13 index12 alt2">
               <code class="python plain">
                formatter
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.Formatter(
               </code>
               <code class="python string">
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number14 index13 alt1">
               <code class="python plain">
                handler.setFormatter(formatter)
               </code>
              </div>
              <div class="line number15 index14 alt2">
              </div>
              <div class="line number16 index15 alt1">
               <code class="python comments">
                # add the handlers to the logger
               </code>
              </div>
              <div class="line number17 index16 alt2">
              </div>
              <div class="line number18 index17 alt1">
               <code class="python plain">
                logger.addHandler(handler)
               </code>
              </div>
              <div class="line number19 index18 alt2">
              </div>
              <div class="line number20 index19 alt1">
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Hello baby'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        标准库模块中提供了许多的 handler ，你可以将记录发送到邮箱甚至发送到一个远程的服务器。你也可以实现自己的记录 handler 。这里将不具体讲述实现的细节，你可以参考官方文档：
        <a href="http://docs.python.org/2/howto/logging.html#logging-basic-tutorial">
         Basci Turial
        </a>
        、
        <a href="http://docs.python.org/2/howto/logging.html#logging-advanced-tutorial">
         Advanced Tutorial
        </a>
        与
        <a href="http://docs.python.org/2/howto/logging-cookbook.html#logging-cookbook">
         Logging Cookbook
        </a>
        。
       </p>
       <h3>
        以合适的等级输出日志记录
       </h3>
       <p>
        有了灵活的日志记录模块后，你可以按适当的等级将日志记录输出到任何地方然后配置它们。那么你可能会问，什么是合适的等级呢？在这儿我将分享一些我的经验。
       </p>
       <p>
        大多数的情况下，你都不想阅读日志中的太多细节。因此，只有你在调试过程中才会使用 DEBUG 等级。我只使用 DEBUG 获取详细的调试信息，特别是当数据量很大或者频率很高的时候，比如算法内部每个循环的中间状态。
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_378595">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                complex_algorithm(items):
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                for
               </code>
               <code class="python plain">
                i, item
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python functions">
                enumerate
               </code>
               <code class="python plain">
                (items):
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                # do some complex algorithm computation
               </code>
              </div>
              <div class="line number4 index3 alt1">
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.debug(
               </code>
               <code class="python string">
                '%s iteration, item=%s'
               </code>
               <code class="python plain">
                , i, item)
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        在处理请求或者服务器状态变化等日常事务中，我会使用 INFO 等级。
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_782930">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                handle_request(request):
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Handling request %s'
               </code>
               <code class="python plain">
                , request)
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                # handle request here
               </code>
              </div>
              <div class="line number4 index3 alt1">
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                result
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python string">
                'result'
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Return result: %s'
               </code>
               <code class="python plain">
                , result)
               </code>
              </div>
              <div class="line number7 index6 alt2">
              </div>
              <div class="line number8 index7 alt1">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                start_service():
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Starting service at port %s ...'
               </code>
               <code class="python plain">
                , port)
               </code>
              </div>
              <div class="line number10 index9 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                service.start()
               </code>
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Service is started'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        当发生很重要的事件，但是并不是错误时，我会使用 WARNING 。比如，当用户登录密码错误时，或者连接变慢时。
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_180072">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                authenticate(user_name, password, ip_address):
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                if
               </code>
               <code class="python plain">
                user_name !
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                USER_NAME
               </code>
               <code class="python keyword">
                and
               </code>
               <code class="python plain">
                password !
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                PASSWORD:
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.warn(
               </code>
               <code class="python string">
                'Login attempt to %s from IP %s'
               </code>
               <code class="python plain">
                , user_name, ip_address)
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                return
               </code>
               <code class="python color1">
                False
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                # do authentication here
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        有错误发生时肯定会使用 ERROR 等级了。比如抛出异常，IO 操作失败或者连接问题等。
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_339778">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                get_user_by_id(user_id):
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                user
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                db.read_user(user_id)
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                if
               </code>
               <code class="python plain">
                user
               </code>
               <code class="python keyword">
                is
               </code>
               <code class="python color1">
                None
               </code>
               <code class="python plain">
                :
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.error(
               </code>
               <code class="python string">
                'Cannot find user with user_id=%s'
               </code>
               <code class="python plain">
                , user_id)
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                return
               </code>
               <code class="python plain">
                user
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                return
               </code>
               <code class="python plain">
                user
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        我很少使用 CRITIAL 。当一些特别糟糕的事情发生时，你可以使用这个级别来记录。比方说，内存耗尽，磁盘满了或者核危机（希望永远别发生 :S）。
       </p>
       <h3>
        使用 __name__ 作为 logger 的名称
       </h3>
       <p>
        虽然不是非得将 logger 的名称设置为 __name__ ，但是这样做会给我们带来诸多益处。在 python 中，变量 __name__ 的名称就是当前模块的名称。比如，在模块 “foo.bar.my_module” 中调用 logger.getLogger(__name__) 等价于调用logger.getLogger(“foo.bar.my_module”) 。当你需要配置 logger 时，你可以配置到 “foo” 中，这样包 foo 中的所有模块都会使用相同的配置。当你在读日志文件的时候，你就能够明白消息到底来自于哪一个模块。
       </p>
       <h3>
        捕捉异常并使用 traceback 记录它
       </h3>
       <p>
        出问题的时候记录下来是个好习惯，但是如果没有 traceback ，那么它一点儿用也没有。你应该捕获异常并用 traceback 把它们记录下来。比如下面这个例子：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_22431">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                try
               </code>
               <code class="python plain">
                :
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                open
               </code>
               <code class="python plain">
                (
               </code>
               <code class="python string">
                '/path/to/does/not/exist'
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python string">
                'rb'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python keyword">
                except
               </code>
               <code class="python plain">
                (SystemExit, KeyboardInterrupt):
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                raise
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python keyword">
                except
               </code>
               <code class="python plain">
                Exception, e:
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.error(
               </code>
               <code class="python string">
                'Failed to open file'
               </code>
               <code class="python plain">
                , exc_info
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python color1">
                True
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        使用参数 exc_info=true 调用 logger 方法, traceback 会输出到 logger 中。你可以看到下面的结果：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_338481">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                ERROR:__main__:Failed to
               </code>
               <code class="python functions">
                open
               </code>
               <code class="python functions">
                file
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                Traceback (most recent call last):
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                File
               </code>
               <code class="python string">
                "example.py"
               </code>
               <code class="python plain">
                , line
               </code>
               <code class="python value">
                6
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python keyword">
                in
               </code>
               <code class="python plain">
                &lt;module&gt;
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python functions">
                open
               </code>
               <code class="python plain">
                (
               </code>
               <code class="python string">
                '/path/to/does/not/exist'
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python string">
                'rb'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python plain">
                IOError: [Errno
               </code>
               <code class="python value">
                2
               </code>
               <code class="python plain">
                ] No such
               </code>
               <code class="python functions">
                file
               </code>
               <code class="python keyword">
                or
               </code>
               <code class="python plain">
                directory:
               </code>
               <code class="python string">
                '/path/to/does/not/exist'
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        你也可以调用 logger.exception(msg, _args)，它等价于 logger.error(msg, exc_info=True, _args)。
       </p>
       <p>
        千万不要在模块层次获取 Logger，除非 disable_existing_loggers 被设置为 False
       </p>
       <p>
        你可以看到很多在模块层次获取 logger 的例子（在这篇文章我也使用了很多，但这仅仅为了让示例更短一些）。它们看上去没什么坏处，但事实上，这儿是有陷阱的 – 如果你像这样在模块中使用 Logger，Python 会保留从文件中读入配置前所有创建的所有 logger。
       </p>
       <p>
        my_module.py
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_69328">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging
               </code>
              </div>
              <div class="line number2 index1 alt1">
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number4 index3 alt1">
              </div>
              <div class="line number5 index4 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                foo():
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Hi, foo'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number7 index6 alt2">
              </div>
              <div class="line number8 index7 alt1">
               <code class="python keyword">
                class
               </code>
               <code class="python plain">
                Bar(
               </code>
               <code class="python functions">
                object
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                bar(
               </code>
               <code class="python color1">
                self
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number10 index9 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Hi, bar'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        main.py
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_233539">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging
               </code>
              </div>
              <div class="line number2 index1 alt1">
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number4 index3 alt1">
              </div>
              <div class="line number5 index4 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                foo():
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Hi, foo'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number7 index6 alt2">
              </div>
              <div class="line number8 index7 alt1">
               <code class="python keyword">
                class
               </code>
               <code class="python plain">
                Bar(
               </code>
               <code class="python functions">
                object
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                bar(
               </code>
               <code class="python color1">
                self
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number10 index9 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Hi, bar'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        logging.ini
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_372834">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
             <div class="line number21 index20 alt2">
              21
             </div>
             <div class="line number22 index21 alt1">
              22
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                [loggers]
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python plain">
                keys
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                root
               </code>
              </div>
              <div class="line number3 index2 alt2">
              </div>
              <div class="line number4 index3 alt1">
               <code class="python plain">
                [handlers]
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python plain">
                keys
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                consoleHandler
               </code>
              </div>
              <div class="line number6 index5 alt1">
              </div>
              <div class="line number7 index6 alt2">
               <code class="python plain">
                [formatters]
               </code>
              </div>
              <div class="line number8 index7 alt1">
               <code class="python plain">
                keys
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                simpleFormatter
               </code>
              </div>
              <div class="line number9 index8 alt2">
              </div>
              <div class="line number10 index9 alt1">
               <code class="python plain">
                [logger_root]
               </code>
              </div>
              <div class="line number11 index10 alt2">
               <code class="python plain">
                level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                DEBUG
               </code>
              </div>
              <div class="line number12 index11 alt1">
               <code class="python plain">
                handlers
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                consoleHandler
               </code>
              </div>
              <div class="line number13 index12 alt2">
              </div>
              <div class="line number14 index13 alt1">
               <code class="python plain">
                [handler_consoleHandler]
               </code>
              </div>
              <div class="line number15 index14 alt2">
               <code class="python keyword">
                class
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                StreamHandler
               </code>
              </div>
              <div class="line number16 index15 alt1">
               <code class="python plain">
                level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                DEBUG
               </code>
              </div>
              <div class="line number17 index16 alt2">
               <code class="python plain">
                formatter
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                simpleFormatter
               </code>
              </div>
              <div class="line number18 index17 alt1">
               <code class="python plain">
                args
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                (sys.stdout,)
               </code>
              </div>
              <div class="line number19 index18 alt2">
              </div>
              <div class="line number20 index19 alt1">
               <code class="python plain">
                [formatter_simpleFormatter]
               </code>
              </div>
              <div class="line number21 index20 alt2">
               <code class="python functions">
                format
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python keyword">
                %
               </code>
               <code class="python plain">
                (asctime)s
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python keyword">
                %
               </code>
               <code class="python plain">
                (name)s
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python keyword">
                %
               </code>
               <code class="python plain">
                (levelname)s
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python keyword">
                %
               </code>
               <code class="python plain">
                (message)s
               </code>
              </div>
              <div class="line number22 index21 alt1">
               <code class="python plain">
                datefmt
               </code>
               <code class="python keyword">
                =
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        本应该在日志中看到记录，但是你却什么也没有看到。为什么呢？这就是因为你在模块层次创建了 logger，然后你又在加载日志配置文件之前就导入了模块。logging.fileConfig 与 logging.dictConfig 默认情况下会使得已经存在的 logger 失效。所以，这些配置信息不会应用到你的 Logger 上。你最好只在你需要 logger 的时候才获得它。反正创建或者取得 logger 的成本很低。你可以这样写你的代码：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_830367">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging
               </code>
              </div>
              <div class="line number2 index1 alt1">
              </div>
              <div class="line number3 index2 alt2">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                foo():
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'Hi, foo'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number6 index5 alt1">
              </div>
              <div class="line number7 index6 alt2">
               <code class="python keyword">
                class
               </code>
               <code class="python plain">
                Bar(
               </code>
               <code class="python functions">
                object
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number8 index7 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                __init__(
               </code>
               <code class="python color1">
                self
               </code>
               <code class="python plain">
                , logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python color1">
                None
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python color1">
                self
               </code>
               <code class="python plain">
                .logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                or
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number10 index9 alt1">
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                bar(
               </code>
               <code class="python color1">
                self
               </code>
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number12 index11 alt1">
               <code class="python spaces">
               </code>
               <code class="python color1">
                self
               </code>
               <code class="python plain">
                .logger.info(
               </code>
               <code class="python string">
                'Hi, bar'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        这样，logger 就会在你加载配置后才会被创建。这样配置信息就可以正常应用。
       </p>
       <p>
        python2.7 之后的版本中 fileConfg 与 dictConfig 都新添加了 “disable_existing_loggers” 参数，将其设置为 False，上面提到的问题就可以解决了。例如：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_181252">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
             <div class="line number21 index20 alt2">
              21
             </div>
             <div class="line number22 index21 alt1">
              22
             </div>
             <div class="line number23 index22 alt2">
              23
             </div>
             <div class="line number24 index23 alt1">
              24
             </div>
             <div class="line number25 index24 alt2">
              25
             </div>
             <div class="line number26 index25 alt1">
              26
             </div>
             <div class="line number27 index26 alt2">
              27
             </div>
             <div class="line number28 index27 alt1">
              28
             </div>
             <div class="line number29 index28 alt2">
              29
             </div>
             <div class="line number30 index29 alt1">
              30
             </div>
             <div class="line number31 index30 alt2">
              31
             </div>
             <div class="line number32 index31 alt1">
              32
             </div>
             <div class="line number33 index32 alt2">
              33
             </div>
             <div class="line number34 index33 alt1">
              34
             </div>
             <div class="line number35 index34 alt2">
              35
             </div>
             <div class="line number36 index35 alt1">
              36
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging.config
               </code>
              </div>
              <div class="line number3 index2 alt2">
              </div>
              <div class="line number4 index3 alt1">
               <code class="python plain">
                logger
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.getLogger(__name__)
               </code>
              </div>
              <div class="line number5 index4 alt2">
              </div>
              <div class="line number6 index5 alt1">
               <code class="python comments">
                # load config from file
               </code>
              </div>
              <div class="line number7 index6 alt2">
              </div>
              <div class="line number8 index7 alt1">
               <code class="python comments">
                # logging.config.fileConfig('logging.ini', disable_existing_loggers=False)
               </code>
              </div>
              <div class="line number9 index8 alt2">
              </div>
              <div class="line number10 index9 alt1">
               <code class="python comments">
                # or, for dictConfig
               </code>
              </div>
              <div class="line number11 index10 alt2">
              </div>
              <div class="line number12 index11 alt1">
               <code class="python plain">
                logging.config.dictConfig({
               </code>
              </div>
              <div class="line number13 index12 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'version'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                1
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number14 index13 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                'disable_existing_loggers'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python color1">
                False
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python comments">
                # this fixes the problem
               </code>
              </div>
              <div class="line number15 index14 alt2">
              </div>
              <div class="line number16 index15 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                'formatters'
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number17 index16 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'standard'
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number18 index17 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                'format'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
               </code>
              </div>
              <div class="line number19 index18 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number20 index19 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number21 index20 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'handlers'
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number22 index21 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                'default'
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number23 index22 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'level'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                'INFO'
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number24 index23 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                'class'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                'logging.StreamHandler'
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number25 index24 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number26 index25 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number27 index26 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'loggers'
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number28 index27 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                '': {
               </code>
              </div>
              <div class="line number29 index28 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'handlers'
               </code>
               <code class="python plain">
                : [
               </code>
               <code class="python string">
                'default'
               </code>
               <code class="python plain">
                ],
               </code>
              </div>
              <div class="line number30 index29 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                'level'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                'INFO'
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number31 index30 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                'propagate'
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python color1">
                True
               </code>
              </div>
              <div class="line number32 index31 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number33 index32 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number34 index33 alt1">
               <code class="python plain">
                })
               </code>
              </div>
              <div class="line number35 index34 alt2">
              </div>
              <div class="line number36 index35 alt1">
               <code class="python plain">
                logger.info(
               </code>
               <code class="python string">
                'It works!'
               </code>
               <code class="python plain">
                )
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <h3>
        使用 JSON 或者 YAML 记录配置
       </h3>
       <p>
        虽然你可以在 python 代码中配置你的日志系统，但是这样并不够灵活。最好的方法是使用一个配置文件来配置。在 Python2.7 及之后的版本中，你可以从字典中加载 logging 配置。这也就意味着你可以从 JSON 或者 YAML 文件中加载日志的配置。尽管你还能用原来 .ini 文件来配置，但是它既很难读也很难写。下面我给你们看一个用 JSON 和 YAML 文件配置的例子:
       </p>
       <p>
        logging.json
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_683062">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
             <div class="line number21 index20 alt2">
              21
             </div>
             <div class="line number22 index21 alt1">
              22
             </div>
             <div class="line number23 index22 alt2">
              23
             </div>
             <div class="line number24 index23 alt1">
              24
             </div>
             <div class="line number25 index24 alt2">
              25
             </div>
             <div class="line number26 index25 alt1">
              26
             </div>
             <div class="line number27 index26 alt2">
              27
             </div>
             <div class="line number28 index27 alt1">
              28
             </div>
             <div class="line number29 index28 alt2">
              29
             </div>
             <div class="line number30 index29 alt1">
              30
             </div>
             <div class="line number31 index30 alt2">
              31
             </div>
             <div class="line number32 index31 alt1">
              32
             </div>
             <div class="line number33 index32 alt2">
              33
             </div>
             <div class="line number34 index33 alt1">
              34
             </div>
             <div class="line number35 index34 alt2">
              35
             </div>
             <div class="line number36 index35 alt1">
              36
             </div>
             <div class="line number37 index36 alt2">
              37
             </div>
             <div class="line number38 index37 alt1">
              38
             </div>
             <div class="line number39 index38 alt2">
              39
             </div>
             <div class="line number40 index39 alt1">
              40
             </div>
             <div class="line number41 index40 alt2">
              41
             </div>
             <div class="line number42 index41 alt1">
              42
             </div>
             <div class="line number43 index42 alt2">
              43
             </div>
             <div class="line number44 index43 alt1">
              44
             </div>
             <div class="line number45 index44 alt2">
              45
             </div>
             <div class="line number46 index45 alt1">
              46
             </div>
             <div class="line number47 index46 alt2">
              47
             </div>
             <div class="line number48 index47 alt1">
              48
             </div>
             <div class="line number49 index48 alt2">
              49
             </div>
             <div class="line number50 index49 alt1">
              50
             </div>
             <div class="line number51 index50 alt2">
              51
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                {
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "version"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                1
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number3 index2 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "disable_existing_loggers"
               </code>
               <code class="python plain">
                : false,
               </code>
              </div>
              <div class="line number4 index3 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "formatters"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "simple"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "format"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
               </code>
              </div>
              <div class="line number7 index6 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number8 index7 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number9 index8 alt2">
              </div>
              <div class="line number10 index9 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "handlers"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "console"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number12 index11 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "class"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "logging.StreamHandler"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number13 index12 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "level"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "DEBUG"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number14 index13 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "formatter"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "simple"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number15 index14 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "stream"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "ext://sys.stdout"
               </code>
              </div>
              <div class="line number16 index15 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number17 index16 alt2">
              </div>
              <div class="line number18 index17 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "info_file_handler"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number19 index18 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "class"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "logging.handlers.RotatingFileHandler"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number20 index19 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "level"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "INFO"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number21 index20 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "formatter"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "simple"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number22 index21 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "filename"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "info.log"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number23 index22 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "maxBytes"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                10485760
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number24 index23 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "backupCount"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                20
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number25 index24 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "encoding"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "utf8"
               </code>
              </div>
              <div class="line number26 index25 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number27 index26 alt2">
              </div>
              <div class="line number28 index27 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "error_file_handler"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number29 index28 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "class"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "logging.handlers.RotatingFileHandler"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number30 index29 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "level"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "ERROR"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number31 index30 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "formatter"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "simple"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number32 index31 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "filename"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "errors.log"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number33 index32 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "maxBytes"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                10485760
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number34 index33 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "backupCount"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python value">
                20
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number35 index34 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "encoding"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "utf8"
               </code>
              </div>
              <div class="line number36 index35 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number37 index36 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number38 index37 alt1">
              </div>
              <div class="line number39 index38 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "loggers"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number40 index39 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "my_module"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number41 index40 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "level"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "ERROR"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number42 index41 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "handlers"
               </code>
               <code class="python plain">
                : [
               </code>
               <code class="python string">
                "console"
               </code>
               <code class="python plain">
                ],
               </code>
              </div>
              <div class="line number43 index42 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "propagate"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "no"
               </code>
              </div>
              <div class="line number44 index43 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number45 index44 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                },
               </code>
              </div>
              <div class="line number46 index45 alt1">
              </div>
              <div class="line number47 index46 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "root"
               </code>
               <code class="python plain">
                : {
               </code>
              </div>
              <div class="line number48 index47 alt1">
               <code class="python spaces">
               </code>
               <code class="python string">
                "level"
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "INFO"
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number49 index48 alt2">
               <code class="python spaces">
               </code>
               <code class="python string">
                "handlers"
               </code>
               <code class="python plain">
                : [
               </code>
               <code class="python string">
                "console"
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python string">
                "info_file_handler"
               </code>
               <code class="python plain">
                ,
               </code>
               <code class="python string">
                "error_file_handler"
               </code>
               <code class="python plain">
                ]
               </code>
              </div>
              <div class="line number50 index49 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                }
               </code>
              </div>
              <div class="line number51 index50 alt2">
               <code class="python plain">
                }
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        logging.yaml
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_54736">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
             <div class="line number21 index20 alt2">
              21
             </div>
             <div class="line number22 index21 alt1">
              22
             </div>
             <div class="line number23 index22 alt2">
              23
             </div>
             <div class="line number24 index23 alt1">
              24
             </div>
             <div class="line number25 index24 alt2">
              25
             </div>
             <div class="line number26 index25 alt1">
              26
             </div>
             <div class="line number27 index26 alt2">
              27
             </div>
             <div class="line number28 index27 alt1">
              28
             </div>
             <div class="line number29 index28 alt2">
              29
             </div>
             <div class="line number30 index29 alt1">
              30
             </div>
             <div class="line number31 index30 alt2">
              31
             </div>
             <div class="line number32 index31 alt1">
              32
             </div>
             <div class="line number33 index32 alt2">
              33
             </div>
             <div class="line number34 index33 alt1">
              34
             </div>
             <div class="line number35 index34 alt2">
              35
             </div>
             <div class="line number36 index35 alt1">
              36
             </div>
             <div class="line number37 index36 alt2">
              37
             </div>
             <div class="line number38 index37 alt1">
              38
             </div>
             <div class="line number39 index38 alt2">
              39
             </div>
             <div class="line number40 index39 alt1">
              40
             </div>
             <div class="line number41 index40 alt2">
              41
             </div>
             <div class="line number42 index41 alt1">
              42
             </div>
             <div class="line number43 index42 alt2">
              43
             </div>
             <div class="line number44 index43 alt1">
              44
             </div>
             <div class="line number45 index44 alt2">
              45
             </div>
             <div class="line number46 index45 alt1">
              46
             </div>
             <div class="line number47 index46 alt2">
              47
             </div>
             <div class="line number48 index47 alt1">
              48
             </div>
             <div class="line number49 index48 alt2">
              49
             </div>
             <div class="line number50 index49 alt1">
              50
             </div>
             <div class="line number51 index50 alt2">
              51
             </div>
             <div class="line number52 index51 alt1">
              52
             </div>
             <div class="line number53 index52 alt2">
              53
             </div>
             <div class="line number54 index53 alt1">
              54
             </div>
             <div class="line number55 index54 alt2">
              55
             </div>
             <div class="line number56 index55 alt1">
              56
             </div>
             <div class="line number57 index56 alt2">
              57
             </div>
             <div class="line number58 index57 alt1">
              58
             </div>
             <div class="line number59 index58 alt2">
              59
             </div>
             <div class="line number60 index59 alt1">
              60
             </div>
             <div class="line number61 index60 alt2">
              61
             </div>
             <div class="line number62 index61 alt1">
              62
             </div>
             <div class="line number63 index62 alt2">
              63
             </div>
             <div class="line number64 index63 alt1">
              64
             </div>
             <div class="line number65 index64 alt2">
              65
             </div>
             <div class="line number66 index65 alt1">
              66
             </div>
             <div class="line number67 index66 alt2">
              67
             </div>
             <div class="line number68 index67 alt1">
              68
             </div>
             <div class="line number69 index68 alt2">
              69
             </div>
             <div class="line number70 index69 alt1">
              70
             </div>
             <div class="line number71 index70 alt2">
              71
             </div>
             <div class="line number72 index71 alt1">
              72
             </div>
             <div class="line number73 index72 alt2">
              73
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                -
               </code>
               <code class="python keyword">
                -
               </code>
               <code class="python keyword">
                -
               </code>
              </div>
              <div class="line number2 index1 alt1">
              </div>
              <div class="line number3 index2 alt2">
               <code class="python plain">
                version:
               </code>
               <code class="python value">
                1
               </code>
              </div>
              <div class="line number4 index3 alt1">
              </div>
              <div class="line number5 index4 alt2">
               <code class="python plain">
                disable_existing_loggers:
               </code>
               <code class="python color1">
                False
               </code>
              </div>
              <div class="line number6 index5 alt1">
              </div>
              <div class="line number7 index6 alt2">
               <code class="python plain">
                formatters:
               </code>
              </div>
              <div class="line number8 index7 alt1">
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                simple:
               </code>
              </div>
              <div class="line number10 index9 alt1">
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python functions">
                format
               </code>
               <code class="python plain">
                :
               </code>
               <code class="python string">
                "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
               </code>
              </div>
              <div class="line number12 index11 alt1">
              </div>
              <div class="line number13 index12 alt2">
               <code class="python plain">
                handlers:
               </code>
              </div>
              <div class="line number14 index13 alt1">
              </div>
              <div class="line number15 index14 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                console:
               </code>
              </div>
              <div class="line number16 index15 alt1">
              </div>
              <div class="line number17 index16 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                class
               </code>
               <code class="python plain">
                : logging.StreamHandler
               </code>
              </div>
              <div class="line number18 index17 alt1">
              </div>
              <div class="line number19 index18 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                level: DEBUG
               </code>
              </div>
              <div class="line number20 index19 alt1">
              </div>
              <div class="line number21 index20 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                formatter: simple
               </code>
              </div>
              <div class="line number22 index21 alt1">
              </div>
              <div class="line number23 index22 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                stream: ext:
               </code>
               <code class="python keyword">
                /
               </code>
               <code class="python keyword">
                /
               </code>
               <code class="python plain">
                sys.stdout
               </code>
              </div>
              <div class="line number24 index23 alt1">
              </div>
              <div class="line number25 index24 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                info_file_handler:
               </code>
              </div>
              <div class="line number26 index25 alt1">
              </div>
              <div class="line number27 index26 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                class
               </code>
               <code class="python plain">
                : logging.handlers.RotatingFileHandler
               </code>
              </div>
              <div class="line number28 index27 alt1">
              </div>
              <div class="line number29 index28 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                level: INFO
               </code>
              </div>
              <div class="line number30 index29 alt1">
              </div>
              <div class="line number31 index30 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                formatter: simple
               </code>
              </div>
              <div class="line number32 index31 alt1">
              </div>
              <div class="line number33 index32 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                filename: info.log
               </code>
              </div>
              <div class="line number34 index33 alt1">
              </div>
              <div class="line number35 index34 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                maxBytes:
               </code>
               <code class="python value">
                10485760
               </code>
               <code class="python comments">
                # 10MB
               </code>
              </div>
              <div class="line number36 index35 alt1">
              </div>
              <div class="line number37 index36 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                backupCount:
               </code>
               <code class="python value">
                20
               </code>
              </div>
              <div class="line number38 index37 alt1">
              </div>
              <div class="line number39 index38 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                encoding: utf8
               </code>
              </div>
              <div class="line number40 index39 alt1">
              </div>
              <div class="line number41 index40 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                error_file_handler:
               </code>
              </div>
              <div class="line number42 index41 alt1">
              </div>
              <div class="line number43 index42 alt2">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                class
               </code>
               <code class="python plain">
                : logging.handlers.RotatingFileHandler
               </code>
              </div>
              <div class="line number44 index43 alt1">
              </div>
              <div class="line number45 index44 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                level: ERROR
               </code>
              </div>
              <div class="line number46 index45 alt1">
              </div>
              <div class="line number47 index46 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                formatter: simple
               </code>
              </div>
              <div class="line number48 index47 alt1">
              </div>
              <div class="line number49 index48 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                filename: errors.log
               </code>
              </div>
              <div class="line number50 index49 alt1">
              </div>
              <div class="line number51 index50 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                maxBytes:
               </code>
               <code class="python value">
                10485760
               </code>
               <code class="python comments">
                # 10MB
               </code>
              </div>
              <div class="line number52 index51 alt1">
              </div>
              <div class="line number53 index52 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                backupCount:
               </code>
               <code class="python value">
                20
               </code>
              </div>
              <div class="line number54 index53 alt1">
              </div>
              <div class="line number55 index54 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                encoding: utf8
               </code>
              </div>
              <div class="line number56 index55 alt1">
              </div>
              <div class="line number57 index56 alt2">
               <code class="python plain">
                loggers:
               </code>
              </div>
              <div class="line number58 index57 alt1">
              </div>
              <div class="line number59 index58 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                my_module:
               </code>
              </div>
              <div class="line number60 index59 alt1">
              </div>
              <div class="line number61 index60 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                level: ERROR
               </code>
              </div>
              <div class="line number62 index61 alt1">
              </div>
              <div class="line number63 index62 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                handlers: [console]
               </code>
              </div>
              <div class="line number64 index63 alt1">
              </div>
              <div class="line number65 index64 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                propagate: no
               </code>
              </div>
              <div class="line number66 index65 alt1">
              </div>
              <div class="line number67 index66 alt2">
               <code class="python plain">
                root:
               </code>
              </div>
              <div class="line number68 index67 alt1">
              </div>
              <div class="line number69 index68 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                level: INFO
               </code>
              </div>
              <div class="line number70 index69 alt1">
              </div>
              <div class="line number71 index70 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                handlers: [console, info_file_handler, error_file_handler]
               </code>
              </div>
              <div class="line number72 index71 alt1">
              </div>
              <div class="line number73 index72 alt2">
               <code class="python plain">
                ...
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        接下来将展示怎样从 JSON 文件中读入日志的配置信息：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_564860">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
             <div class="line number21 index20 alt2">
              21
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                json
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging.config
               </code>
              </div>
              <div class="line number3 index2 alt2">
              </div>
              <div class="line number4 index3 alt1">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                setup_logging(
               </code>
              </div>
              <div class="line number5 index4 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                default_path
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python string">
                'logging.json'
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number6 index5 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                default_level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.INFO,
               </code>
              </div>
              <div class="line number7 index6 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                env_key
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python string">
                'LOG_CFG'
               </code>
              </div>
              <div class="line number8 index7 alt1">
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                """Setup logging configuration
               </code>
              </div>
              <div class="line number10 index9 alt1">
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                """
               </code>
              </div>
              <div class="line number12 index11 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                path
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                default_path
               </code>
              </div>
              <div class="line number13 index12 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                value
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                os.getenv(env_key,
               </code>
               <code class="python color1">
                None
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number14 index13 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                if
               </code>
               <code class="python plain">
                value:
               </code>
              </div>
              <div class="line number15 index14 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                path
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                value
               </code>
              </div>
              <div class="line number16 index15 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                if
               </code>
               <code class="python plain">
                os.path.exists(path):
               </code>
              </div>
              <div class="line number17 index16 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                with
               </code>
               <code class="python functions">
                open
               </code>
               <code class="python plain">
                (path,
               </code>
               <code class="python string">
                'rt'
               </code>
               <code class="python plain">
                ) as f:
               </code>
              </div>
              <div class="line number18 index17 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                config
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                json.load(f)
               </code>
              </div>
              <div class="line number19 index18 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logging.config.dictConfig(config)
               </code>
              </div>
              <div class="line number20 index19 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                else
               </code>
               <code class="python plain">
                :
               </code>
              </div>
              <div class="line number21 index20 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logging.basicConfig(level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                default_level)
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        使用 JSON 的一个优点就是 json是一个标准库，你不需要额外安装它。但是从我个人来说，我比较喜欢 YAML 一些。它无论是读起来还是写起来都比较容易。你也可以使用下面的方法来加载一个 YAML 配置文件：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_668125">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
             <div class="line number2 index1 alt1">
              2
             </div>
             <div class="line number3 index2 alt2">
              3
             </div>
             <div class="line number4 index3 alt1">
              4
             </div>
             <div class="line number5 index4 alt2">
              5
             </div>
             <div class="line number6 index5 alt1">
              6
             </div>
             <div class="line number7 index6 alt2">
              7
             </div>
             <div class="line number8 index7 alt1">
              8
             </div>
             <div class="line number9 index8 alt2">
              9
             </div>
             <div class="line number10 index9 alt1">
              10
             </div>
             <div class="line number11 index10 alt2">
              11
             </div>
             <div class="line number12 index11 alt1">
              12
             </div>
             <div class="line number13 index12 alt2">
              13
             </div>
             <div class="line number14 index13 alt1">
              14
             </div>
             <div class="line number15 index14 alt2">
              15
             </div>
             <div class="line number16 index15 alt1">
              16
             </div>
             <div class="line number17 index16 alt2">
              17
             </div>
             <div class="line number18 index17 alt1">
              18
             </div>
             <div class="line number19 index18 alt2">
              19
             </div>
             <div class="line number20 index19 alt1">
              20
             </div>
             <div class="line number21 index20 alt2">
              21
             </div>
             <div class="line number22 index21 alt1">
              22
             </div>
             <div class="line number23 index22 alt2">
              23
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                os
               </code>
              </div>
              <div class="line number2 index1 alt1">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                logging.config
               </code>
              </div>
              <div class="line number3 index2 alt2">
              </div>
              <div class="line number4 index3 alt1">
               <code class="python keyword">
                import
               </code>
               <code class="python plain">
                yaml
               </code>
              </div>
              <div class="line number5 index4 alt2">
              </div>
              <div class="line number6 index5 alt1">
               <code class="python keyword">
                def
               </code>
               <code class="python plain">
                setup_logging(
               </code>
              </div>
              <div class="line number7 index6 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                default_path
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python string">
                'logging.yaml'
               </code>
               <code class="python plain">
                ,
               </code>
              </div>
              <div class="line number8 index7 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                default_level
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                logging.INFO,
               </code>
              </div>
              <div class="line number9 index8 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                env_key
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python string">
                'LOG_CFG'
               </code>
              </div>
              <div class="line number10 index9 alt1">
               <code class="python plain">
                ):
               </code>
              </div>
              <div class="line number11 index10 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                """Setup logging configuration
               </code>
              </div>
              <div class="line number12 index11 alt1">
              </div>
              <div class="line number13 index12 alt2">
               <code class="python spaces">
               </code>
               <code class="python comments">
                """
               </code>
              </div>
              <div class="line number14 index13 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                path
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                default_path
               </code>
              </div>
              <div class="line number15 index14 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                value
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                os.getenv(env_key,
               </code>
               <code class="python color1">
                None
               </code>
               <code class="python plain">
                )
               </code>
              </div>
              <div class="line number16 index15 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                if
               </code>
               <code class="python plain">
                value:
               </code>
              </div>
              <div class="line number17 index16 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                path
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                value
               </code>
              </div>
              <div class="line number18 index17 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                if
               </code>
               <code class="python plain">
                os.path.exists(path):
               </code>
              </div>
              <div class="line number19 index18 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                with
               </code>
               <code class="python functions">
                open
               </code>
               <code class="python plain">
                (path,
               </code>
               <code class="python string">
                'rt'
               </code>
               <code class="python plain">
                ) as f:
               </code>
              </div>
              <div class="line number20 index19 alt1">
               <code class="python spaces">
               </code>
               <code class="python plain">
                config
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                yaml.load(f.read())
               </code>
              </div>
              <div class="line number21 index20 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                logging.config.dictConfig(config)
               </code>
              </div>
              <div class="line number22 index21 alt1">
               <code class="python spaces">
               </code>
               <code class="python keyword">
                else
               </code>
               <code class="python plain">
                :
               </code>
              </div>
              <div class="line number23 index22 alt2">
               <code class="python spaces">
               </code>
               <code class="python plain">
                lo
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        接下来，你就可以在运行程序的时候调用 setup_logging 来启动日志记录了。它默认会读取 logging.json 或 logging.yaml 文件 。你也可以设置环境变量 LOG_CCFG 从指定路径加载日志配置。例如：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_611379">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                LOG_CFG
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                my_logging.json python my_server.py
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        如果你喜欢 YAML：
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_554869">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
             <div class="line number1 index0 alt2">
              1
             </div>
            </td>
            <td class="code">
             <div class="container">
              <div class="line number1 index0 alt2">
               <code class="python plain">
                LOG_CFG
               </code>
               <code class="python keyword">
                =
               </code>
               <code class="python plain">
                my_logging.yaml python my_server.py
               </code>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <h3>
        使用旋转文件句柄
       </h3>
       <p>
        如果你用 FileHandler 写日志，文件的大小会随着时间推移而不断增大。最终有一天它会占满你所有的磁盘空间。为了避免这种情况出现，你可以在你的生成环境中使用 RotatingFileHandler 替代 FileHandler。
       </p>
       <h3>
        如果你有多个服务器可以启用一个专用的日志服务器
       </h3>
       <p>
        当你有多个服务器和不同的日志文件时，你可以创建一个集中式的日志系统来收集重要的（大多数情况是警告或者错误消息）信息。然后通过监测这些日志信息，你就可以很容易地发现系统中的问题了。
       </p>
       <h3>
        总结
       </h3>
       <p>
        Python 的日志库设计得如此之好，真是让人欣慰，我觉得这是标准库中最好的一部分了，你不得不选择它。它很灵活，你可以用你自己的 handler 或者 filter。已经有很多的第三方的 handler 了，比如 pyzmq 提供的 ZeroMQ 日志句柄，它允许你通过 zmq 套接字发送日志消息。如果你还不知道怎么正确的使用日志系统，这篇文章将会非常有用。有了很好的日志记录实践，你就能非常容易地发现系统中的问题。这是很非常值得投资的。:)
       </p>
       <p>
        <a href="http://www.jobbole.com/members/scbzyhx">
         yhx
        </a>
        翻译 英文出处：
        <a href="http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python" target="_blank">
         Victor lin
        </a>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20824.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t018630756a7e263b33-300x165.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20824.html" rel="bookmark" title="如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘">
         如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20820.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/1-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20820.html" rel="bookmark" title="人们对Python在企业级开发中的10大误解">
         人们对Python在企业级开发中的10大误解
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20811.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t0133fcacae8523307b_副本-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20811.html" rel="bookmark" title="大神亲传：26条深度学习的金科玉律！">
         大神亲传：26条深度学习的金科玉律！
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20808.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/640.webp-11-300x137.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20808.html" rel="bookmark" title="我们是如何在一张地图上表现86万个数据的">
         我们是如何在一张地图上表现86万个数据的
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F19906.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/19906.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/19906.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>